;;;; lang


;;(add-to-list 'auto-mode-alist '("\\.[hc]\\(pp\\)?\\'" . simpc-mode))
(setq-default c-basic-offset 2)

;;设置一键编译 可以自行添加参数 难背考场不建议使用 不建议依赖一键编译
;;(defun compile-acm ()(interactive)(compile (format "g++ -o a.exe %s -g -Wall && a.exe" (buffer-name))))
;;(global-set-key (kbd "C-c r") 'compile-acm)
(rc/require 'quickrun)
(use-package quickrun
  :after prog-mode
  :commands (quickrun)
  :bind ("<f5>" . quickrun)
  :config
  (quickrun-add-command "c++/c20"
    '((:command . "g++")
      (:exec . ("%c -std=c++20 %o -o %e %s"
                "%e %a"))
      (:remove . ("%e")))
    :default "c++")
)


;;; c-mode
(setq-default c-basic-offset 2
              c-default-style '((java-mode . "java")
                                (awk-mode . "awk")
                                (other . "bsd")))

(add-hook 'c-mode-hook (lambda ()
                         (interactive)
                         (c-toggle-comment-style -1)))
;; lua
(rc/require 'lua-mode)
(use-package lua-mode
  :mode ("\\.lua\\'" . lua-mode))

;; hy
;; (rc/require 'hy-mode)
;; (use-package hy-mode
;;   :mode ("\\.hy\\'" . hy-mode))

;; ocaml
;; (rc/require 'caml-mode)
;; (use-package caml-mode
;;   :mode ("\\.ml\\'" . caml-mode))

;; nim
;; (rc/require 'nim-mode)
;; (use-package nim-mode
;; :mode ("\\.nim\\'" . nim-mode))

;; zig
;; (rc/require 'zig-mode)
;; (use-package zig-mode
;; :mode ("\\.zig\\'" . zig-mode))



;; (straight-use-package '(c3-ts-mode
;;    :host github :repo "c3lang/c3-ts-mode"))
;; (use-package c3-ts-mode
;;   :mode ("\\.c3\\'" . c3-ts-mode)
;;   :config
;;   (setq c3-ts-mode-indent-offset 2)
;;   ;; treesit source
;;   (add-to-list 'treesit-language-source-alist
;;     '(c3 "https://githubfast.com/c3lang/tree-sitter-c3"))
;; )

;; typst
;; (straight-use-package '(typst-mode :host github :repo "Ziqi-Yang/typst-mode.el"))
;; (use-package typst-mode
;;   :mode ("\\.tps\\'" . typst-mode))

;; odin
;; (straight-use-package '(odin-mode
;;    :host github :repo "mattt-b/odin-mode"))
;; (use-package odin-mode
;;   :mode ("\\.odin\\'" . odin-mode))

;;;  ------------------- web dev

;; TailwindCSS 插件配置
;; (rc/require 'lsp-tailwindcss)
;; (use-package lsp-tailwindcss
;;   :after lsp-mode
;;   :init
;;   (setq lsp-tailwindcss-add-on-mode t))

;; 快速编写 HTML 代码
;; (rc/require 'emmet-mode)
;; (use-package emmet-mode
;;   :after web-mode
;;   :commands emmet-mode
;;   :init
;;   (setq emmet-expand-jsx-className? t)
;;   :config
;;   (unbind-key "<C-return>" emmet-mode-keymap))
;;
;; (rc/require 'typescript-mode)
;; (use-package typescript-mode
;;   :mode "\\.ts[x]\\'"
;;   :hook (typescript-mode . lsp-deferred)
;;   :config
;;   (setq typescript-indent-level 2)
;; )
;;
;; (use-package js-mode
;;   :ensure nil
;;   :mode "\\.[c|m]js[x]\\'"
;;   :hook
;;   (js-mode . lsp-deferred)
;;   :config
;;   (setq js-indent-level 2)
;; )


;; (use-package restclient
;;   :mode ("\\.http\\'" . restclient-mode)
;;   :config
;;   (require 'restclient-jq)
;;   (with-eval-after-load 'company
;;     (use-package company-restclient
;;       :defines company-backends
;;       :init (add-to-list 'company-backends 'company-restclient))))

;; (rc/require 'web-mode)
;; (use-package web-mode
;;   :mode (
;;          ("\\.svelte\\'" . web-mode)
;;          ;("\\.[tj]s[x]?\\'" . web-mode)
;;          ("\\.astro\\'" . web-mode)
;;          )
;;   :config
;;   (setq web-mode-markup-indent-offset 2)
;;   (setq web-mode-css-indent-offset 2)
;;   (setq web-mode-code-indent-offset 2)
;;   (setq web-mode-script-padding 0)
;;   (setq web-mode-style-padding 0)
;; )

;; (straight-use-package '(vue-mode
;;    :host github :repo "AdamNiederer/vue-mode"))
;; (use-package vue-mode
;;               :mode ("\\.vue\\'" . vue-mode)
;;                :config
;;                (setq vue-mode-excluded-packages '())
;;                ;; 0, 1, or 2, representing (respectively) none, low, and high coloring
;;                (setq mmm-submode-decoration-level 0))
;; https://github.com/emacs-lsp/lsp-mode/issues/4313#issuecomment-2051461893
;; if it dose not work, try `M-: (lsp-package-ensure  'typescript nil nil) RET`
;; (with-eval-after-load 'lsp-volar
;;   (lsp-dependency 'typescript
;;                   '(:npm :package "typescript"
;;                          :path "tsserver")))
;;
;; (rc/require 'add-node-modules-path)
;; (use-package add-node-modules-path
;;   :hook ((web-mode js-mode js2-mode) . add-node-modules-path))

;; cangjie
;; (use-package cj-mode
;;   :mode "\\.cj\\'"
;;   :config
;;   (with-eval-after-load 'lsp-mode
;;   (add-to-list 'lsp-language-id-configuration '(cj-mode . "cangjie"))
;;
;;   (lsp-register-client
;;    (make-lsp-client
;;     :new-connection (lsp-stdio-connection
;;                      (lambda ()
;;                         (list "LSPServer.exe" "src" "--disableAutoImport" "-V")))
;;     :activation-fn (lsp-activate-on "cangjie")
;;     :server-id 'LSPServer)))
;;)

;; go
(rc/require 'go-mode 'go-tag 'godoctor)
(use-package go-mode
  :mode "\\.go\\'"
  :preface
   (defun vd/go-lsp-start()
    (add-hook 'before-save-hook #'lsp-format-buffer t t)
    (add-hook 'before-save-hook #'lsp-organize-imports t t)
    ;(lsp-deferred)
    )
  :hook
  (go-ts-mode . vd/go-lsp-start)
  :custom
  (go-ts-mode-indent-offset 2)
  :config
  (setq lsp-go-analyses '(
                          (nilness . t)
                          (shadow . t)
                          (unusedwrite . t)
                          (fieldalignment . t)
                                       )
        lsp-go-codelenses '(
                          (test . t)
                          (tidy . t)
                          (upgrade_dependency . t)
                          (vendor . t)
                          (run_govulncheck . t)
                                       )
        )
)
(use-package go-tag :after go-mode)
(use-package godoctor :after go-mode)

;; rust
(rc/require 'rustic)
(use-package rustic
  :mode ("\\.rs\\'" . rustic)
  :config
  (setq rustic-format-on-save nil)
  :custom
  (rustic-cargo-use-last-stored-arguments t)
  (rustic-analyzer-command '("rustup" "run" "nightly" "rust-analyzer")))
;; python
(rc/require 'python)
(use-package python
  :mode ("\\.py\\'" . python-mode)
  ;:interpreter ("python3" . python-mode)
  :config

  (with-eval-after-load 'lsp-mode
  (add-to-list 'lsp-language-id-configuration '(python-mode . "python"))

  (lsp-register-client
   (make-lsp-client
    :new-connection (lsp-stdio-connection
                     (lambda ()
                        (list "delance-langserver" "--stdio")))
    :activation-fn (lsp-activate-on "python")
    :server-id 'delance)))
  ;; for debug
  ;(require 'dap-python)
  )


(rc/require 'pyvenv)
(use-package pyvenv
  :after python
  :config
   (setenv "WORKON_HOME" (expand-file-name "e:/miniforge3/envs"))
  ;(setq python-shell-interpreter "python3")  ; （可选）更改解释器名字
  (pyvenv-mode t)
  ;; （可选）如果希望启动后激活 miniconda 的 base 环境，就使用如下的 hook
;;    :hook
;;    (python-mode . (lambda () (pyvenv-workon "..")))
)
;; (rc/require 'lsp-pyright)
;; (use-package lsp-pyright
;;   :config
;;   :hook
;;   (python-mode . (lambda ()
;; 		  (require 'lsp-pyright)
;; 		  )))



(provide 'init-lang)
